<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>文件上传</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastify-js/1.11.2/toastify.min.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/toastify-js/1.11.2/toastify.min.js"></script>
</head>
<body>

<input type="text" id="url" placeholder="请输入文件URL">
<button onclick="uploadFile()">上传文件</button>

<script>
    function uploadFile() {
        const url = document.getElementById('url').value;

        // 发送 POST 请求到后台
        fetch('/files/uploadByUrl', {
            method: 'POST',
            headers: {
                'Content-Type': 'application/json',
            },
            body: JSON.stringify({ url: url })
        })
            .then(response => response.json())
            .then(data => {
                // 检查返回的响应
                if (data.code !== "000000") {
                    // 如果返回的code不是"000000"，就显示错误信息
                    Toastify({
                        text: data.desc, // 显示错误描述
                        backgroundColor: "red",
                        duration: 3000
                    }).showToast();
                } else {
                    // 上传成功
                    Toastify({
                        text: "上传成功！",
                        backgroundColor: "green",
                        duration: 3000
                    }).showToast();
                }
            })
            .catch(error => {
                console.error('Error:', error);
            });
    }
</script>

</body>
</html>
